package com.wanwu.channel.notify.controller;

import com.alibaba.fastjson.JSON;
import com.wanwu.channel.common.enums.AlarmTypeEnum;
import com.wanwu.channel.core.tool.AlarmPoolUtil;
import com.wanwu.monitor.api.util.AlarmMsgModelUtil;
import com.wanwu.monitor.api.enums.SystemEnum;
import com.wanwu.monitor.api.util.vo.AlarmMsgVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 钉钉告警池测试入口
 * @author chenshunxing
 * @date 2020/08/12 16:42
 */
@RestController
@RequestMapping("/")
public class AlarmPoolTestController {

    @Resource
    private AlarmPoolUtil alarmPoolUtil;

    //测试机器人
    private static final String dingkey1="468d47979a3b1ba2d001df2fbcbc9710e8b9935ba084ae99cb38d0813e5027c7";

    //测试机器人2
    private static final String dingkey2="4c514bc589853d0c072b5c503172772ac470c931ba1a2edd79447ff02f842057";

    @Value("${mq.ding.appKey}")
    private String dingKey;

    /**
     * 给缓冲池中添加告警信息 默认间隔30秒自动发，测试时如果需要立马发：调用alarmPoolUtil.sendAndClear()方法。
     */
    @RequestMapping(value = "addAlarmTest")
    @ResponseBody
    public String addAlarmTest(){

        return "success";

    }

    /**
     * 给缓冲池中添加告警信息 默认间隔30秒自动发。
     */
    @RequestMapping(value = "addAlarmTestOnline")
    @ResponseBody
    public String addAlarmTestOnline(){
        for(int i=0;i<2;i++){
            AlarmMsgVo alarmMsgVo = new AlarmMsgVo.Builder().head("告警上线测试：渠道系统告警：【支付宝】回调状态与本地不一致")
                    .field("bizOrderNo", new Date().getTime()).field("【支付宝】回调异常状态", new Date().getTime()).build();
            alarmPoolUtil.addGatherAlarm(dingkey1, AlarmTypeEnum.ALIPAYNOTIFYSTATUSDIFF, alarmMsgVo);
        }
        return "success";
    }

}